// TOWN SCRIPT
//    Town 1

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;


//Stop them going back to t0
beginstate 10;
	message_dialog("You've already explored that section of the caves; heading back there instead of pressing would be foolish. You turn back around, and move on.","");
	block_entry(1);
break;

//Move to next town	
beginstate 11;
	move_to_new_town(2,24,40);
break;

//Gate-slamming
beginstate 12;
	if(get_flag(1,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you walk down this path heading away from the ruined inn you suddenly hear a clanging sound from behind you. You spin around and watch as the gates you just passed through slam shut.",0);
		add_dialog_str(1,"It's unlikely that they just decided to close on their own which means that you've either just sprung a trap, or somebody closed them manually.",0);
		add_dialog_str(2,"Whichever it is, it is clear that somebody doesn't want you to be able to turn back. In your experience, that usually means that there'll be trouble ahead...",0);
		run_dialog(1);
		play_sound(99);
		flip_terrain(7,18);
		flip_terrain(8,18);
		flip_terrain(9,18);
		set_flag(1,0,1);
	}
break;

//Entry to cave
beginstate 13;
	if(get_flag(1,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"The tunnel that you were following suddenly opens up into a wider cavern. Peering through the gloom, you can make out a smallish pool of water just in front of you, but that's not grabs your attention.",0);
		add_dialog_str(1,"To the south, there is some kind of stone wall, and it's definitely man-made. You move towards it, thanking your good fortune that you found somewhere to rest so quickly.",0);
		run_dialog(1);
		set_flag(1,1,1);
	}
break;

//Near the inn 
beginstate 14;
	if(get_flag(1,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"You get close enough to the building to take a proper look at it, and immediately take a step back. It's a wreck. The entire north-west corner has collapsed, and you can make out... you take a swallow.",0);
		add_dialog_str(1,"The rubble, dirt and wreckage of the building (which, judging from the furniture and large amounts of glasses and mugs was probably an inn) is littered with the yellowing bones of the deceased.",0);
		add_dialog_str(2,"Whether they died when the building collapsed/was destroyed or not, you can't tell, but they have certainly been there for a while.",0);
		run_dialog(1);
		set_flag(1,2,1);
	}
break;
		
//Boxes in common room.
beginstate 15;
	if(get_flag(1,3) == 0) {
		message_dialog("This box is completely empty, which would suggest that either it was never used whilst the inn was open, or else somebody has emptied it since the inn was wrecked.","");
		set_flag(1,3,1);
	} else {
		message_dialog("You have already looked in here.","");
	}
break;

//Wheel
beginstate 16;
	if(get_flag(1,4) == 0) {
		message_dialog("This huge wheel, you assume, controls the gates just outside. However, you've no way of knowing because it's stuck fast - it'd take somebody with incredible strength to move it.","You leave it be.");
		set_flag(1,4,1);
	} else {
		message_dialog("Try as you might, you still can't budge the wheel at all. You move on.","");
	}
break;

//Poison!
beginstate 17; 
	if(get_flag(1,5) == 0) {
		message_dialog("There is a small cluster of mushrooms and fungi thriving on the bank of this small pond. You take a look at them, hoping to find something that might be useful in a potion.","Unfortunately almost everything here is highly poisonous. You carefully walk around the patch - the last thing you want to do is knock some toxic spores into the air.");
		set_flag(1,5,1);
	} else {
		message_dialog("You walk around the mushroom patch, being careful not to knock any poisonous spores into the air.","");
	}
break;

//Woodstacks
beginstate 18;
	if(get_flag(1,6) == 0) {
		message_dialog("This section of the cave is littered with a series of woodpiles. Wood is still relatively rare in Avernum, but not nearly as much as it used to be.","Whoever owned this inn was wealthy indeed if they could afford to have this amount just lying around.");
		set_flag(1,6,1);
	}
break;